home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / RCS / Semaphore.h,v < prev    next >
Text File  |  1989-02-23  |  2KB  |  143 lines

  1. head     3.2;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    grunwald:3.2; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 3.2
  10. date     89.02.20.15.37.13;  author grunwald;  state Exp;
  11. branches ;
  12. next     3.1;
  13.  
  14. 3.1
  15. date     88.12.20.13.50.15;  author grunwald;  state Exp;
  16. branches ;
  17. next     1.2;
  18.  
  19. 1.2
  20. date     88.10.30.13.06.03;  author grunwald;  state Exp;
  21. branches ;
  22. next     1.1;
  23.  
  24. 1.1
  25. date     88.09.18.16.42.14;  author grunwald;  state Exp;
  26. branches ;
  27. next     ;
  28.  
  29.  
  30. desc
  31. @@
  32.  
  33.  
  34. 3.2
  35. log
  36. @Start using Gnu library heaps for schedulers
  37. @
  38. text
  39. @// This may look like C code, but it is really -*- C++ -*-
  40. // 
  41. // Copyright (C) 1988 University of Illinois, Urbana, Illinois
  42. //
  43. // written by Dirk Grunwald (grunwald@@cs.uiuc.edu)
  44. //
  45. #ifndef SEMAPHOREH
  46. #define SEMAPHOREH
  47.  
  48. //
  49. //    Semaphore.h
  50. //
  51. //    This implements a general counting semaphore. Each semaphore has
  52. //    a value known as 'count', which can be initialized to any value.
  53. //
  54. //    When count is < 1, and a process attempts to reserve the semaphore,
  55. //    that process is suspended. If count > 1, then the process continues.
  56. //    In either case, the count is decremented.
  57. //
  58. //    When releasing a semaphore, the count is incremented. If the count
  59. //    was less than 1, a single waiting process (if any is waiting) is
  60. //    allowed to proceed.
  61. // 
  62.  
  63. #include "ReserveByException.h"
  64. #include "SpinLock.h"
  65. #include "ThreadContainer.h"
  66.  
  67. class Semaphore : public ReserveByException {
  68.  
  69. protected:
  70.     SpinLock lock;
  71.     ThreadContainer *pScheduler;
  72.     int pCount;
  73.  
  74. private:
  75.     virtual bool reserveByException( Thread *byWho );
  76.     
  77. public :
  78.  
  79.     Semaphore(int count = 1,
  80.           ThreadContainer *scheduler = 0,
  81.           bool debug = FALSE);
  82.     virtual ~Semaphore();
  83.  
  84.     virtual void reserve();
  85.     virtual void release();
  86.     virtual bool reserveNoBlock();
  87.  
  88.     virtual unsigned size();
  89.  
  90.     //
  91.     //    You should not change the count when threads are blocked
  92.     //
  93.     virtual int count();
  94.     virtual int count(int count);
  95.     virtual void incrCount(int increment);
  96.  
  97.     bool isEmpty();
  98.  
  99.     virtual void classPrintOn(ostream&);
  100. };
  101.  
  102. inline bool
  103. Semaphore::isEmpty()
  104. {
  105.     return( size() == 0);
  106. }
  107.  
  108. #endif SEMAPHOREH
  109. @
  110.  
  111.  
  112. 3.1
  113. log
  114. @Steay version
  115. @
  116. text
  117. @d51 4
  118. d57 2
  119. @
  120.  
  121.  
  122. 1.2
  123. log
  124. @*** empty log message ***
  125. @
  126. text
  127. @@
  128.  
  129.  
  130. 1.1
  131. log
  132. @Initial revision
  133. @
  134. text
  135. @d1 6
  136. d26 1
  137. a26 1
  138. #include "HardSpinLock.h"
  139. d32 1
  140. a32 1
  141.     HardSpinLock lock;
  142. @
  143.